package com.tong.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tong.entity.Article;
import com.tong.entity.vo.ArticleQuery;
import com.tong.result.Result;
import com.tong.service.ArticleService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author tong
 * @since 2021-09-29
 */
@RestController
@RequestMapping("/blog/article")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    @ApiOperation("分页条件查询文章")
    @PostMapping("listArticle/{current}/{limit}")
    public Result listArticle(@PathVariable Long current,
                              @PathVariable Long limit,
                              @RequestBody ArticleQuery articleQuery) {
        Page<Article> articlePage = new Page<>(current, limit);
        articleService.listArticle(articlePage, articleQuery);
        List<Article> articleList = articlePage.getRecords();
        long total = articlePage.getTotal();
        return Result.ok().data("articleList",articleList).data("total",total);
    }
}

